# 定义过滤方法，过滤热门新闻显示的颜色
from functools import wraps

from flask import g ,current_app,session



def index_class(index):
    if index == 1:
        return "first"
    elif index == 2:
        return "second"
    elif index == 3:
        return "third"
    else:
        return ""

# # 定义登录对象装饰器
def user_login_data(view_func):
    @wraps(view_func)
    def wrapper(*args,**kwargs):
        user_id = session.get("user_id")

        # 获取用户登陆数据
        user = None
        if user_id:
            try:
                from info.models import User

                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        # 使用g对象保存用户数据
        g.user = user
        return view_func(*args, **kwargs)
    return wrapper